const ProductModel = require("../../bin/models/ProductModel")

const ProductService = {
    add : async ({title,introduction,detail,cover,editTime})=>{
        return ProductModel.create({
            title,introduction,cover,editTime,detail
        })
    },

    getList:async ({_id})=>{
        return _id ? ProductModel.find({_id}) : ProductModel.find({})
    },

    delList:async ({_id})=>{
        return ProductModel.deleteOne({
            _id
        })
    },

    updateList:async ({ _id,title,introduction,cover,editTime,detail})=>{
        if(cover){
            return ProductModel.updateOne({_id},{title,introduction,cover,editTime,detail})
        }else{
            return ProductModel.updateOne({_id},{title,introduction,editTime,detail})
        }
    }
}

module.exports = ProductService